import React, { Component } from 'react'

export default class Rcc extends Component {
  // constructor() {
  //   super()
  //   this.handleClick = this.handleClick.bind(this)
  // }
  state = {
    msg: 'hello react'
  }
  render() {
    return (
      <div>
        <h1>Rcc</h1>
        <button onClick={this.handleClick}>没有改变this指向</button>
        <br />
        <button onClick={this.handleClick.bind(this)}>
          1.通过bind改变this的指向
        </button>
        <br />
        <button onClick={() => this.handleClick()}>
          2. 通过箭头函数改变this的指向
        </button>
        <br />
        <button onClick={this.handleClick}>3. 直接以箭头函数的方式定义</button>
      </div>
    )
  }

  // handleClick() {
  //   // console.log(this)
  //   console.log(this.state.msg)
  // }
  handleClick = () => {
    console.log(this.state.msg)
  }
}
